function a(a) {
    return a && a.__esModule ? a : {
        default: a
    };
}

var e = a(require("../../api/api.js")), t = a(require("../../utils/util.js")), n = a(require("../../utils/filter.js")), r = require("../../config/constants.js"), s = getApp();

Page({
    data: {
        captchaText: "获取验证码",
        cellphone: "",
        captcha_code: "",
        timeFlag: 60,
        waiting: !0,
        phoneFromWrap: !1,
        userPersonalInfo: {},
        hasUserInfo: !1
    },
    switchTab: function(a) {
        this.setData({
            currentNavtab: a.currentTarget.dataset.idx
        });
    },
    toggleSignType: function(a) {
        this.setData({
            phoneFromWrap: !this.data.phoneFromWrap
        });
    },
    toggleResetPassword: function(a) {
        wx.navigateTo({
            url: "../reset_password/reset_password"
        });
    },
    bindViewTap: function() {
        wx.navigateTo({
            url: "../logs/logs"
        });
    },
    onLoad: function() {
        var a = this;
        (wx.getStorageSync("token") || "") && this.getUserStatistics(), wx.getStorage({
            key: "userPersonalInfo",
            success: function(e) {
                a.setData({
                    userPersonalInfo: e.data,
                    hasUserInfo: !0
                });
            }
        });
    },
    getCaptcha: function() {
        var a = this, t = {
            phonenumber: this.data.cellphone,
            phonenumber_country_prefix: "+86",
            type: "verify"
        };
        e.default.getCaptchaViaPhone({
            data: t,
            success: function(e) {
                e && e.data.data.success && a.countDown();
            }
        });
    },
    signViaPhone: function() {
        var a = this, t = this.data.cellphone, o = wx.getStorageSync("userInfo").unionid, i = "mobile" + t.substr(t.length - 4), u = {
            unionid: o,
            phone_number_country_prefix: "+86",
            phone_number: t,
            captcha_code: this.data.captcha_code,
            nickname: i
        };
        e.default.signViaPhone({
            method: "POST",
            data: u,
            success: function(e) {
                if (e && e.data.data) {
                    var t = e.header["x-token"] || e.header["X-Token"], o = e.header["v-token"] || e.header["V-Token"], i = e.data.data;
                    i.user_avatar_file = r.CDN_ADDR + i.avatar_file_name + "_Avatar.jpg", i.purchase_sum = n.default.convertCurrencyToCNY(i.purchase_sum, s.globalData.currencyDatum), 
                    s.globalData.userPersonalInfo = i, s.globalData.token = t, s.globalData.vtoken = o, 
                    wx.setStorage({
                        key: "userPersonalInfo",
                        data: i
                    }), wx.setStorage({
                        key: "token",
                        data: t
                    }), wx.setStorage({
                        key: "vtoken",
                        data: o
                    }), a.setData({
                        userPersonalInfo: i,
                        hasUserInfo: !0
                    });
                } else {
                    if ("ErrorCaptcha" === e.data.error.type) u = "验证码错误"; else var u = e.data.error.msg;
                    a.setData({
                        errorInfo: u,
                        hasUserInfo: !1
                    });
                }
            }
        });
    },
    signViaEmail: function() {
        var a = this, t = wx.getStorageSync("userInfo").unionid, o = {
            LOGIN_PA_USERNAME: this.data.user_email,
            LOGIN_PA_PASSWORD: this.data.user_password,
            unionid: t
        };
        e.default.signViaEmail({
            method: "POST",
            data: o,
            success: function(e) {
                if (e && e.data.data) {
                    var t = e.header["x-token"] || e.header["X-Token"], o = e.header["v-token"] || e.header["V-Token"], i = e.data.data;
                    i.user_avatar_file = r.CDN_ADDR + i.avatar_file_name + "_Avatar.jpg", i.purchase_sum = n.default.convertCurrencyToCNY(i.purchase_sum, s.globalData.currencyDatum), 
                    s.globalData.userPersonalInfo = i, s.globalData.token = t, s.globalData.vtoken = o, 
                    wx.setStorage({
                        key: "userPersonalInfo",
                        data: i
                    }), wx.setStorage({
                        key: "token",
                        data: t
                    }), wx.setStorage({
                        key: "vtoken",
                        data: o
                    }), a.setData({
                        userPersonalInfo: i,
                        hasUserInfo: !0
                    });
                } else {
                    var u = e.data.error.msg;
                    a.setData({
                        errorInfo: u,
                        hasUserInfo: !1
                    });
                }
            }
        });
    },
    emailinput: function(a) {
        var e = a.detail.value;
        if (/^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,63}$/i.test(e)) t = ""; else var t = "请输入正确的邮箱";
        this.setData({
            user_email: e,
            errorInfo: t
        });
    },
    passwordInput: function(a) {
        this.setData({
            user_password: a.detail.value
        });
    },
    phoneinput: function(a) {
        var e = a.detail.value;
        if (/1[3|5|7|8|][0-9]{9}/.test(e)) t = ""; else var t = "请输入正确的手机号码";
        this.setData({
            cellphone: e,
            errorInfo: t
        });
    },
    captchaCodeInput: function(a) {
        var e = a.detail.value;
        this.setData({
            captcha_code: e
        });
    },
    countDown: function() {
        var a = this, e = this.data.timeFlag, t = setInterval(function() {
            e > 0 && e <= 60 ? (e--, a.setData({
                captchaText: e + "s"
            }), a.setData({
                waiting: !0
            })) : (clearInterval(t), e = 60, a.setData({
                captchaText: "重新发送"
            }), a.setData({
                waiting: !1
            }));
        }, 1e3);
    },
    onImageError: function(a) {
        var e = this;
        t.default.errImgFun(a, e);
    },
    getUserStatistics: function() {
        var a = this, t = {
            i_token: s.globalData.token
        };
        e.default.getUserStatistics({
            data: t,
            success: function(e) {
                if (e && e.data.data) {
                    var t = e.data.data;
                    t.payment_account_cny = n.default.convertCurrencyToCNY(t.payment_account.available_itc_usd, s.globalData.currencyDatum), 
                    a.setData({
                        userStatisticsDatum: t
                    });
                }
            }
        });
    },
    onShareAppMessage: function(a) {
        return "button" === a.from && console.log(a.target), {
            title: "italki",
            path: "/pages/teacher/teacher",
            success: function(a) {
                console.log("sucess");
            },
            fail: function(a) {
                console.log("fail");
            }
        };
    },
    bindToWallet: function(a) {
        wx.navigateTo({
            url: "../wallet/wallet"
        });
    },
    bindToMessage: function(a) {
        wx.navigateTo({
            url: "../messages/messages"
        });
    },
    bindToReferral: function() {
        wx.navigateTo({
            url: "../referral/referral"
        });
    }
});